package com.zy.explore.sys.domain.mybatis.entity;

import com.zy.explore.common.infrastructure.base.mybatis.MpBaseEntity;
import com.zy.explore.common.infrastructure.util.StrUtil;
import com.zy.explore.sys.interfaces.frm.UserDataScopeQueryFrm;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.annotations.TableName;
import com.baomidou.mybatisplus.enums.IdType;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import javax.persistence.Table;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.Date;
import org.springframework.util.StringUtils;
import java.util.stream.Collectors;

/**
 * 表(sys_user_data_scope)对应的Mybatis ORM实体对象
 *
 * @author 🇨🇳中国印🇨🇳
 * @date 2022年02月01日 17:19:30
 */
@Slf4j
@Entity
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sys_user_data_scope")
@Table(name = "sys_user_data_scope")
public class UserDataScope extends MpBaseEntity<UserDataScope, String> {

    /**
     * 主键
     */
    @Id
    @TableId(type = IdType.ID_WORKER)
    @Column(name = "id")
    private String id;

    /**
     * 用户id
     */
    @Column(name = "user_id")
    private Long userId;

    /**
     * 机构id
     */
    @Column(name = "org_id")
    private Long orgId;


    /**
     * 组装查询条件
     *
     * @param frm 请求参数
     * @return {@link Wrapper<UserDataScope> }
     */
    public static Wrapper<UserDataScope> getWrapper(UserDataScopeQueryFrm frm) {
        // TODO 请按实际需求组装查询条件
        log.warn("TODO 请按实际需求组装查询条件");
        if (frm.getPageNum() == null || frm.getPageNum() <= 0) {
            frm.setPageNum(1);
        }
        if (frm.getPageSize() == null || frm.getPageSize() <= 0) {
            frm.setPageSize(10);
        }
        Wrapper<UserDataScope> wrapper = new EntityWrapper<>();
        if(frm.getId() != null) {
            wrapper.eq(StrUtil.humpToUnderline("id"), frm.getId());
        }
        if(frm.getUserId() != null) {
            wrapper.eq(StrUtil.humpToUnderline("userId"), frm.getUserId());
        }
        if(frm.getOrgId() != null) {
            wrapper.eq(StrUtil.humpToUnderline("orgId"), frm.getOrgId());
        }
        return wrapper;
    }
}